package com.five.wisdomEat.controller;

import cn.hutool.core.util.IdUtil;
import com.five.wisdomEat.entity.Dishes;
import com.five.wisdomEat.entity.DishesApplication;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.service.DishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@CrossOrigin
@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    private DishesService service;

    @GetMapping("/getDishesList")
    public ResponseMessage getDishesAll(String bNumber){

        return service.getDishesAll(bNumber);
    }
    @GetMapping("/selectDishesCount")
    public ResponseMessage selectDishesCount(){
        return service.selectDishesCount();
    }

    @PostMapping("/insertDishes")
    public ResponseMessage insertDishes(String bNumber, String dName, Integer dTypeId, Double dPrice, Integer dCount, String dWeight, String url ){
        Dishes dishes = new Dishes();
        dishes.setBNumber(bNumber);
        dishes.setDNumber(IdUtil.fastSimpleUUID()  );
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDPrice(dPrice);
        dishes.setDCount(dCount);
        dishes.setDWeight(dWeight);
        dishes.setDPhoto(url);
        DishesApplication application = new DishesApplication();
        application.setDaDNumber(dishes.getDNumber());
        application.setDaTime(new Date());
        return service.insertDishes(dishes,application);
    }

    @PostMapping("/updateDishes")
    public ResponseMessage updateDishes(String dNumber, String dName, Integer dTypeId, Double dPrice, Integer dCount, String dWeight, String url ){
        Dishes dishes = new Dishes();
        dishes.setDNumber(dNumber);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDPrice(dPrice);
        dishes.setDCount(dCount);
        dishes.setDWeight(dWeight);
        dishes.setDPhoto(url);
        return service.updateDishes(dishes);
    }

    @PostMapping("/deleteDishes")
    public ResponseMessage deleteDishes(String dNumber){
        return service.deleteDishes(dNumber);
    }

    @PostMapping("/onSaleDishes")
    public ResponseMessage onSaleDishes(String dNumber){
        return service.onSaleDishes(dNumber);
    }

    @PostMapping("/offShelfDishes")
    public ResponseMessage offShelfDishes(String dNumber){
        return service.offShelfDishes(dNumber);
    }

    @GetMapping("/selectDishesListByExample")
    public ResponseMessage selectDishesListByExample(String bNumber,String dNumber, String dName, Integer dTypeId,Integer dStateId ){
        Dishes dishes = new Dishes();
        dishes.setBNumber(bNumber);
        dishes.setDNumber(dNumber);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDStateId(dStateId);
        return service.selectDishesListByExample(dishes);
    }

    @GetMapping("/selectDishesOnSale")
    public ResponseMessage selectDishesOnSale(){
        return service.selectDishesOnSale();
    }

    @GetMapping("/selectDishesByDNumber")
    public ResponseMessage selectDishesByDNumber(String dNumber){
        return service.selectDishesByDNumber(dNumber);
    }


    @GetMapping("/selectOnSaleDishesByExample")
    public ResponseMessage selectOnSaleDishesByExample(String dName,String bName,Integer dTypeId ){
        Dishes dishes = new Dishes();
        dishes.setBName(bName);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        return service.selectOnSaleDishesByExample(dishes);
    }

    @GetMapping("/selectDishesApplication")
    public ResponseMessage selectDishesApplication(){
        return service.selectDishesApplication();
    }

    @PostMapping("/applyDishesApplication")
    public ResponseMessage applyDishesApplication(Integer id,String dNumber){
        DishesApplication application =new DishesApplication();
        application.setId(id);
        return service.applyDishesApplication(application,dNumber);
    }

    @PostMapping("/refuseDishesApplication")
    public ResponseMessage refuseDishesApplication(Integer id, String dNumber){
        DishesApplication application =new DishesApplication();
        application.setId(id);
        return service.refuseDishesApplication(application,dNumber);
    }
}
